In [1]:
from scipy.special import binom
import scipy.stats

In [6]:
# scipy.stats.binom.pmf(x, n, p)
# scipy.stats.hypergeom.pmf(k, M, n, N)

Suppose you have an urn that contains 30 red and 60 blue marbles.

Consider "sampling without replacement". If you draw 5 marbles at once (without putting them back) what is the probability that 3 are blue?


In [12]:
scipy.stats.binom.pmf(3, 5, 2/3)


Out[12]:
0.32921810699588472

In [17]:
N = 90
K = 60
n = 5
k = 3

binom(K, k) * binom(N-K, n-k) / binom(N, n)


Out[17]:
0.33870188691197312

In [16]:
# scipy.stats.hypergeom.pmf(k, N, K, n)
# N: marbles in urn
# K: marbles considered success
# n: number selected
# k: number of successes

N = 90
K = 60
n = 5
k = 3

scipy.stats.hypergeom.pmf(k, N, K, n)


Out[16]:
0.3387018869119775

In [ ]: